package sparrow.indexer;

import org.apache.lucene.*;
import org.apache.lucene.analysis.*;
import org.apache.lucene.analysis.standard.StandardAnalyzer;

import java.io.StringReader;
import java.util.ArrayList;

public class Indexer {

	/**
	 * Returns the indexes for the given <tt>String</tt>
	 */
	public ArrayList<String> indexes(String input) {
		Analyzer analyzer = new StandardAnalyzer();
		Tokenizer tokenizer = new Tokenizer(new StringReader(input));
		Token nextToken = tokenizer.nextToken();

		ArrayList<String> finalOutput = new ArrayList<String>();

		while (nextToken != null) {
			finalOutput.add(nextToken.toString());
			nextToken = tokenizer.nextToken();
		}
	}

	/**
	 * Testing
	 */
	public static void main(String[] args) {
		ArrayList<String> indexes;
		Indexer indexer = new Indexer();

		String testString = "When in the Course of human events it becomes " +
		"necessary for one people to dissolve the political bands which have " +
		"connected them with another and to assume among the powers of the earth, " +
		"the separate and equal station to which the Laws of Nature and of Nature's " +
		"God entitle them, a decent respect to the opinions of mankind requires " +
		"that they should declare the causes which impel them to the separation.";

		indexes = indexer.indexes(testString);

		System.out.println(indexes);
	}
}
